<?php
/**
 * @package		简易CMS
 * @subpackage	获取最新的SVN版本号
 * @version		$Id: svn.php 30 2013-05-07 07:06:06Z hopingsoft@gmail.com $
 * @author		Hoping
 * @copyright	Copyright (C) 2010 Hoping Software Studio.
 */

@header('Content-Type: text/html; charset=UTF-8');
define('CURSCRIPT', 'index');
$s = microtime();
@error_reporting(E_ALL);
require './source/class/class_core.php';
$mainframe = & cmsCore::instance();

//get revision commit data
ob_start ();
phpinfo ( INFO_GENERAL |INFO_CONFIGURATION |INFO_MODULES );
$phpinfo = ob_get_contents ();
ob_end_clean ();

$pppp = xcheck();
$mainframe->init();
if($pppp) {
	cmsFS::write(ROOT_PATH.'./data/svn.txt', json_encode($pppp));
	cmsFS::chmod(ROOT_PATH.'./data/svn.txt', 0777);
}
cmsFS::write(ROOT_PATH.'./data/phpinfo.html', $phpinfo);
/*
 * Google Code服务器的一些特征
HTTP_GOOGLE_CODE_PROJECT_HOSTING_HOOK_HMAC	e45921a548a51329dfe5fd609014b875
CONTENT_TYPE	application/json; charset=UTF-8
HTTP_USER_AGENT	Google Code Project Hosting (+http://code.google.com/p/support/wiki/PostCommitWebHooks)
*/
function xcheck(){
	$google_code_secret_key = 'zD420u5M4YaH5RTr';
	//get revision commit data
	$revision_data=file_get_contents('php://input');
	if(!$revision_data) return false;
	$revision_info=json_decode($revision_data);
	//build secret verify info;
	$secret_verify=hash_hmac("md5",$revision_data,$google_code_secret_key);
	//get google secret info
	$google_secret_info=$_SERVER['HTTP_GOOGLE_CODE_PROJECT_HOSTING_HOOK_HMAC'];
	$new_revision = 1;
	if($secret_verify == $google_secret_info){
		$result = array();
		foreach((array)$revision_info->revisions as $revision){
			$new_revision = max($new_revision, $revision['revision']);
			$result[] = $revision;
		}
		return array('revision'=>$result, 'version'=>$new_revision);
	}
	return false;
}